#@Time : 2020/12/10 10:38
#@Author: sl
#@File : user_update.py
from flask import request
from flask_restful import reqparse

from app.v2.models.UserModel import UserSample
from framework.api.AbstractApi import AbstractApi
from framework import db
from framework.util.InvertUtil import res_copy_model_to_dest

'''
  get 单表更新 请求示例 http://127.0.0.1:8181/v2/userUpdate?name=update123&id=1285923099950198851
'''
# parser = reqparse.RequestParser()  这种验证不好用
# parser.add_argument('name', type=str, required=True)
#parser.parse_args()
class UserUpdate(AbstractApi):
    def handle_get_request(self):
        user = UserSample()
        user.__dict__.update(request.args)
        dbUser=db.session.query(UserSample).get(user.id)#根据id查对象
        res_copy_model_to_dest(user, dbUser)
        db.session.commit()
        return "update success"
